from django.shortcuts import render
from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
from rest_framework.filters import OrderingFilter
from science.models import SciencePopularization
from science.ser import SciencePopularizationSerializer

# 分页配置
class StandardResultsSetPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    max_page_size = 100

# 排序配置
class CustomOrderingFilter(OrderingFilter):
    ordering_params = ('title', 'length')

# 科普视频 ListAPIView
class SciencePopularizationListView(ListAPIView):
    serializer_class = SciencePopularizationSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['title', 'length']

    def get_queryset(self):
        return SciencePopularization.objects.all()